package com.dmgis.qxfw.dataservice.businessservice.prosrv.service.impl;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.sys_config;
import com.dmgis.qxfw.dataservice.businessservice.common.util.JsonUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.StringUtil;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.prosrv.service.IProsrvService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("ProService")
public class ProsrvServiceImpl implements IProsrvService {

	ProcessRequestController pc = new ProcessRequestController();

	@Override
	public List<sys_config> getUrl(sys_config selectKey) {
		// TODO Auto-generated method stub
		List<sys_config> listData = new ArrayList<sys_config>();
		//List<SysConfig> resultList = new ArrayList<SysConfig>();
		Map<String, String> selectParam = new HashMap<String, String>();
		RequestDataBySelect selectRequest = new RequestDataBySelect();
		String[] columns = new String[] { "paramvalue" };
		selectRequest.setColumns(columns);
		// 拼接where字段
		StringBuilder strWhere = new StringBuilder();
		int whereCount = 0;
		if (selectKey.getParamname() != null) {
			strWhere.append(String.format("and paramname='%s'", selectKey.getParamname()));
		}
		if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
			strWhere = strWhere.replace(0, 4, "");
		}
		selectRequest.setParam(strWhere.toString());
		try {
			selectParam.put("method", "sys_config");
			selectParam.put("sqlType", "select");
			selectParam.put("advCode", DbConfig.advCode);
			selectParam.put("param", JsonUtil.object2Json(selectRequest));
			String message = pc.processRequest(selectParam);
			listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sys_config>>() {
			});
		} catch (Exception e) {
			// TODO: handle exception
		}
		return listData;
	}
}
